//创建一个简单的服务器
//内置模块http
const http = require("http");
const fs = require("fs");
const path = require("path");
const mime = require("./mime.json");
const server = http.createServer(function (request,response){
    if( request.url == "/index.html" ){
        response.setHeader("content-type","text/html;charset=utf-8");
        let data = fs.readFileSync("./view/index.html");
        response.write(data);
    } else if( request.url == "/login.html" ){
        response.setHeader("content-type","text/html;charset=utf-8");
        let data = fs.readFileSync("./view/login.html");
        response.write(data);
    } else if( request.url == "/register.html" ){
        response.setHeader("content-type","text/html;charset=utf-8");
        let data = fs.readFileSync("./view/register.html");
        response.write(data);
    } else {
        console.log(path.extname(request.url));
        let extname = path.extname(request.url) ; 
        let content = mime[extname] ; 
        response.setHeader("content-type",content);
        let data = fs.readFileSync("./view"+request.url);
        response.write(data);
    }
    response.end();
});
server.listen(8787);
console.log(1111);
//安装一个nodemon插件，实现自动刷新
